from rest_framework import serializers
from .models import McHospital, McHospitalLevel
from app.hospital_level.serializers import McForeignHospitalLevelSerializer

class McHospitalSerializer(serializers.ModelSerializer):
    # 查询时用完整对象
    level = McForeignHospitalLevelSerializer(read_only=True)

    # 写入时接收 level_id
    level_id = serializers.PrimaryKeyRelatedField(
        queryset=McHospitalLevel.objects.all(), source="level", write_only=True
    )

    class Meta:
        model = McHospital
        fields = '__all__'